package com.gdevelop.samples.hello.client;


import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;

public class HelloController {
  private static final HelloConstants constants = (HelloConstants)GWT.create(HelloConstants.class);

  private transient PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
  private String name;

  public HelloController() {
  }
  
  /* =========== For property change event =========== */
  public void addPropertyChangeListener(PropertyChangeListener listener) {
    changeSupport.addPropertyChangeListener(listener);
  }
  public void addPropertyChangeListener(String propName,
                                        PropertyChangeListener listener) {
    changeSupport.addPropertyChangeListener(propName, listener);
  }
  public void removePropertyChangeListener(PropertyChangeListener listener) {
    changeSupport.removePropertyChangeListener(listener);
  }
  public void removePropertyChangeListener(String propName,
                                           PropertyChangeListener listener) {
    changeSupport.removePropertyChangeListener(propName, listener);
  }

  public HelloConstants getConstants(){
    return constants;
  }
  
  public void sayGreeting(){
    Window.alert(constants.greeting() + " " + (name != null ? name : "gwtXP"));
  }

  public String getName() {
    return this.name;
  }
  public void setName(String name) {
    String oldName = this.name;
    this.name = name;
    changeSupport.firePropertyChange("name", oldName, name);
  }
}
